Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
Why does $.ajax load the [base url + index.html] repetitively when requested relative url is not found

I have a situation where I load a file and move the content of that file to a placeholder in the HTML. The idea is visible in the code below which is the smallest snippet I could think of which mimics the issue.

When executing while the file in the webroot exists, there is no problem.

When executing while the file is non-existent, the webroot index.html starts loading repetitively while I just want it to execute the fail(). It should load nothing. The effect can be reproduced both in FF and in Chrome.

I must be missing something obvious. I used several ajax options (cache, timeout, headers, Crossdomain ), without effect.

My questions are : what causes this effect?
What am I doing wrong (again: I just want it to execute the fail() )?
What can I do to prevent this?

    <script>
        $(function () {
            Promise.all([LoadCUsermenu('CUsermenu.txt')]).then( ()=>{console.log('Promise fullfilled')} );
            console.log('Do the rest of the stuff')
        });

        function LoadCUsermenu(filename) {
            return $.ajax({
                url: filename
            }).done(function (response, responseStatus) {
                console.log('Usermenu present...Loading');
                $('#CUsermenu').html(response)
            }).fail(function (xhr, textStatus, errorThrown) {
                console.log('No Usermenu present...' + textStatus);
                $('#CUsermenu').html("<li>Nothing there</li>")
            })
        }
    </script>
<head>
</head>

<body>
    <ul id='CUsermenu'></ul>
    <div><p>Wil this be loaded repetetively???</p></div>
</body>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!